package com.skymxc.wandroidtodo.page.login;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.BaseExpandableListAdapter;
import android.widget.EditText;

import androidx.annotation.Nullable;

import com.skymxc.wandroidtodo.R;
import com.skymxc.wandroidtodo.databinding.ActivityLoginBinding;
import com.skymxc.wandroidtodo.page.base.BaseActivity;
import com.skymxc.wandroidtodo.page.main.MainActivity;
import com.skymxc.wandroidtodo.page.register.RegisterActivity;

/**
 * <p>
 *
 * </p>
 *
 * @author 孟祥超
 * <p>
 * date: 2021/12/2  6:54 上午
 */
public class LoginActivity extends BaseActivity<LoginPresenter> implements LoginContact.LoginView, View.OnClickListener {

    private ActivityLoginBinding mBinding;



    @Override
    protected void initView() {
        super.initView();
        mBinding = ActivityLoginBinding.inflate(getLayoutInflater());
        setContentView(mBinding.getRoot());
        mBinding.loginBtnRegister.setOnClickListener(this);
        mBinding.loginBtnLogin.setOnClickListener(this);
    }

    @Override
    protected LoginPresenter initPresenter() {
        return new LoginPresenter(getApplication());
    }

    @Override
    public void loginSuccess() {
        hideProgress();
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.login_btn_login:
                String password = mBinding.loginEtPassword.getText().toString();
                String username = mBinding.loginEtUsername.getText().toString();
                if (TextUtils.isEmpty(username)) {
                    showConfirm("请输入用户名");
                    return;
                }
                if (TextUtils.isEmpty(password)) {
                    showConfirm("请输入密码");
                    return;
                }
                mPresenter.login(username, password);
                break;
            case R.id.login_btn_register:
                Intent intent = new Intent(this, RegisterActivity.class);
                startActivity(intent);
                break;
        }
    }
}
